package com.zh.authresource.controller;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.UUID;

/**
 * 共享给外部的资源
 */
@Slf4j
@RestController
@RequestMapping("/share")
public class SharedController {

    @GetMapping("/book")
    public List<Book> bookList(String sign) {
        log.info("call bookList() ... sign = " + sign);

        Book xyj = new Book("西游记", "师徒四人西天取经");
        Book sgyy = new Book("三国演义", "三国之间的纷乱故事");
        Book shz = new Book("水浒传", "一群好汉的江湖事迹");
        Book hlm = new Book("红楼梦", "晚清家族内部琐事");
        return List.of(xyj, sgyy, shz, hlm);
    }

    @Getter
    static class Book {
        private String id;
        private String title;
        private String content;

        public Book(String title, String content) {
            this.id = UUID.randomUUID().toString().substring(24);
            this.title = title;
            this.content = content;
        }
    }
}
